package com.zcxy.quartz.task;

import com.zcxy.common.core.domain.entity.SysUser;
import com.zcxy.edu.domain.EduStudent;
import com.zcxy.edu.domain.EduTeacher;
import com.zcxy.edu.service.IEduOrgService;
import com.zcxy.edu.service.IEduStudentService;
import com.zcxy.edu.service.IEduTeacherService;
import com.zcxy.edu.service.IEduTokenService;
import com.zcxy.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.zcxy.common.utils.StringUtils;

import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * 定时任务调度测试
 *
 * @author ruoyi
 */
@Component("ryTask")
public class RyTask
{

    @Autowired
    private IEduTokenService eduTokenService;

    @Autowired
    private IEduStudentService eduStudentService;

    @Autowired
    private IEduTeacherService eduTeacherService;

    @Autowired
    private IEduOrgService eduOrgService;

    @Autowired
    private ISysUserService sysUserService;

    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
    {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params)
    {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams()
    {
        System.out.println("执行无参方法");
    }

    public void refreshToken(){
        eduTokenService.saveToken();
    }

    public void refreshPOAToken(){
        eduTokenService.savePOAToken();
    }

    // 学生、老师、机构数据
    public void selectAndSaveStudentApiData() throws UnsupportedEncodingException {
        eduStudentService.selectAndSaveApiData();
    }

    // 老师数据
    public void selectAndSaveTeacherApiData() throws UnsupportedEncodingException {
        eduTeacherService.selectAndSaveApiData();
    }

    // 机构数据
    public void selectAndSaveOrgApiData() throws UnsupportedEncodingException {
        eduOrgService.selectAndSaveApiData();
    }

    // 老师短信
    public void sendTeacherSMS() throws UnsupportedEncodingException {
        eduTeacherService.sendTeacherSMS();
    }

    // 老师短信重发
    public void reTryTeacherSMS() throws UnsupportedEncodingException {
        eduTeacherService.reTryTeacherSMS();
    }

    public void updateData(){
        List<EduStudent> eduStudentList = eduStudentService.selectEduStudentList(new EduStudent());
        for(EduStudent eduStudent : eduStudentList){
            //插入用户表
            SysUser sysUser = new SysUser();
            sysUser.setUserName(eduStudent.getXH());
            sysUser.setNickName(eduStudent.getXM());
            sysUser.setCreateBy("定时任务");
            sysUser.setDelFlag("0");
            sysUser.setRemark("学生");

            Long[] roleIds = new Long[] {101l};
            sysUser.setRoleIds(roleIds);
            sysUserService.saveCenterUser(sysUser);
            System.out.println("更新成功"+eduStudent.getXM());
        }
        List<EduTeacher> eduTeacherList = eduTeacherService.selectEduTeacherList(new EduTeacher());
        for(EduTeacher eduTeacher : eduTeacherList){
            //插入用户表
            SysUser sysUser = new SysUser();
            sysUser.setUserName(eduTeacher.getGH());
            sysUser.setNickName(eduTeacher.getXM());
            sysUser.setCreateBy("定时任务");
            sysUser.setDelFlag("0");
            sysUser.setRemark("教师");

            Long[] roleIds = new Long[] {100l};
            sysUser.setRoleIds(roleIds);
            sysUserService.saveCenterUser(sysUser);
            System.out.println("更新成功"+eduTeacher.getXM());
        }
    }
}
